﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using NPOI.Util.Collections;
using Prism.Events;
using SoonCode.FocusTest.Events;
using SoonCode.FocusTest.Models;
using MessageBox = HandyControl.Controls.MessageBox;

namespace SoonCode.FocusTest.Views
{
    /// <summary>
    /// Login.xaml 的交互逻辑
    /// </summary>
    public partial class Login : BaseWindow
    {
        private IEventAggregator _eventAggregator;
        private SubscriptionToken eventToken;
        public Login(IEventAggregator eventAggregator)
        {
            InitializeComponent();
            _eventAggregator = eventAggregator;
            this.eventToken=this._eventAggregator.GetEvent<LoginEvent>().Subscribe(OnLogin);
            this.Closed += Login_Closed;
        }

        private void Login_Closed(object? sender, EventArgs e)
        {
            this._eventAggregator.GetEvent<LoginEvent>().Unsubscribe(this.eventToken);
        }

        public void OnLogin(UserInfo user)
        {
            DialogResult = true;
            this.Close();
        }
        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            var result=MessageBox.Show(this,"确定要退出系统吗？", "系统提示", MessageBoxButton.YesNo, MessageBoxImage.Question);
            if (result == MessageBoxResult.Yes)
            {
                this.Close();
            }
        }
    }
}
